<%@page import="com.antexpress.bean.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Ant Express</title>
        <link rel="shortcut icon" href="static/img/ant-logo.png">
        <link href="static/css/style.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/edbox.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <%
            if(Authentication.isLogin(session)){
                response.sendRedirect("home.jsp");
            }
        %>
        <div class="container">
            <div>
                <a href="index.jsp"><img src="static/img/logo.png" style="height: 60px; margin-top: 20px;margin-left: 50px;"/></a>
            </div>
            <div style="margin-top: 20px; margin-bottom: 50px;">
                <div class="inline-block bullentin-box">
                    
                </div>
                <div class="inline-block login-box">
                    <div class="login-box-top">
                        <span>Enterprise Login</span>
                    </div>
                    <div style="padding: 20px;">
                        <form>
                            <input id="input-username" type="text" class="input-auto" name="username" placeholder="Username" minlength="6" maxlength="18"/><br/>
                            <input id="input-password" type="password" class="input-auto mt-20" name="password" placeholder="Password" minlength="6" maxlength="12"/><br/>
                            <input id="input-verifycode" type="text" class="input-short mt-20" name="code" placeholder="VerifyCode" maxlength="6"/>
                            <img src="emp/login_verifycode.do" id="imgCode" style="cursor: pointer;vertical-align: bottom;margin-left: 20px;" title="Verify code" onclick="myRefersh(this)"><br/>
                            <input id="input-remember" type="checkbox" class="mt-20" name="remember"/><label for="input-remember" style="margin-left: 10px;cursor:pointer;">Remember me?</label><br/>
                            <input id="bt-login" type="submit" value="Login" class="btn btn-primary mt-20" style="padding: 10px 20px;font-size: 12pt;"/>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="copyright">
            &copy; 2018 QDU-NIIT MASTER
        </div>
        <div class="backstretch">
        </div>
        <script type="text/javascript" src="static/js/jquery.js"></script>
        <script type="text/javascript" src="static/js/jquery.cookie.js"></script>
        <script src="static/js/jquery.edbox.js" type="text/javascript"></script>
        <script type="text/javascript">
            
            $("#bt-login").click(function(check){
                check.preventDefault();
                if($("#input-username").val() === ""||$("#input-password").val()==="") {
                    $.edbox({ warning: 'Username or password id empty!' });
                    return;
                }else if($("#input-verifycode").val()===""){
                    $.edbox({ warning: 'Verify code is empty!' });
                    return;
                }
                $.ajax({
                    url: "${pageContext.request.contextPath}/emp/login.do",
                    data: {
                        "username": $("#input-username").val(),
                        "password": $("#input-password").val(),
                        "verifycode": $("#input-verifycode").val(),
                        "remember": $("#input-remember").is(':checked')
                    },
                    type: "POST",
                    dataType: "json",
                    success: function(result) {
                        if(result.status === 1) {
                            location.reload();
                        }else {
                            $.edbox({ warning: result.msg });
                            $("#imgCode").click();
                        }
                    },
                    error: function() {
                        $.edbox({ warning: 'Login failed!' });
                    }
                });
            });
            
            function myRefersh(e) {
                const source = e.src ; 
                var index = source.indexOf( "?" ) ;
                if( index > -1 ) { 
                    var s = source.substring( 0 , index ) ;
                    var date = new Date(); 
                    var time = date.getTime() ; 
                    e.src = s + "?time=" + time ; 

                } else {  
                    var date = new Date();  
                    e.src = source + "?time=" + date.getTime(); 
                }
            }
        </script>
    </body>
</html>
